package cn.atzxc.qy.controller;

import cn.atzxc.qy.domain.ResponseResult;
import cn.atzxc.qy.domain.Task;
import cn.atzxc.qy.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/pay")
public class PayController {
    @Autowired
    private TaskService taskService;

    //用户发布任务，点击提交订单后，开始支付，把用户发布的任务 从未付款 - 待接单
    @PostMapping("/taskPay")
    public ResponseResult taskPay(@RequestHeader("token") String token, @RequestHeader("taskCode") String taskCode){

        int num = taskService.upTaskPayStatus(token,taskCode);
        if (num > 0){
            return new ResponseResult(200,"付款成功");

        }

        return new ResponseResult(400,"付款失败");

    }

    //取消任务
    @PostMapping("/taskPayCancel")
    public ResponseResult taskPayCancel(@RequestHeader("token") String token, @RequestHeader("taskCode") String taskCode){
        int num = taskService.upTaskPayStatusCancel(token,taskCode);
        if (num > 0){
            return new ResponseResult(200,"取消成功");

        }
        return new ResponseResult(400,"取消失败");
    }



}
